package com.nemo.fenxiangs.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nemo.fenxiangs.po.User;
import com.nemo.fenxiangs.service.UserService;

@Controller
public class LoginController {
	@Autowired
	private UserService userService;
	//登陆
	@RequestMapping("/login")
	public String login(HttpSession session, String username, String password) throws Exception{
		List<User> userList = userService.findUserList();
		for (User user : userList) {
			if(username.equals(user.getName())&password.equals(user.getPassword())){
				session.setAttribute("username", username);
				return "redirect:/jsp/items/main.jsp";
			}
		}	
		return "redirect:/jsp/login.jsp";
	}
	
	// 退出
		@RequestMapping("/logout")
	public String logout(HttpSession session) throws Exception {

			// 清除session
			session.invalidate();

			// 重定向到商品列表页面
			return "redirect:/jsp/login.jsp";
	}
}
